package com.service.bank.controller;



import com.client.model.pojo.bank.ArBankCardPassword;
import com.client.model.pojo.bank.ArBankcard;
import com.client.model.pojo.bank.ArCardtype;
import com.client.model.pojo.bank.Money;
import com.client.model.system.ArBankcardTypeVo;
import com.client.model.system.ElectronicUserVo;
import com.client.model.system.ArElectronicBankCardVo;
import com.client.model.vo.common.Result;
import com.client.model.vo.common.ResultCodeEnum;
import com.service.bank.service.ArCardtypeService;
import com.service.bank.service.ArElectronicService;
import io.swagger.v3.oas.annotations.tags.Tag;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.*;

/**
 * @Author 董慧珍
 * @Date 2024/04/02
 * @Version 1.0
 **/
@RestController
@RequestMapping("/airui/api/openAccount")
@Tag(name = "开户")
public class OpenAccountController {
    @Autowired
    private ArElectronicService arElectronicService;
    @Autowired
    private RedisTemplate<String,String> redisTemplate;
    @Autowired
    private ArCardtypeService arCardtypeService;
    /**
     * 开户
     * @return
     */
    @PostMapping("/kaihu")
    public Result kaihu(@RequestBody ElectronicUserVo electronicUserVo,@RequestHeader String token){
        System.err.println(electronicUserVo);
        System.err.println(token);
        boolean a =this.arElectronicService.findByNameAndMobile(electronicUserVo,token);
        if (a){
            return Result.build(a,ResultCodeEnum.SUCCESS);
        }
        return Result.build(a,ResultCodeEnum.USER_NAME_IS_EXISTS);

    }
    /**
     * 设置支付密码
     * @return
     */
    @PostMapping("/payPassword")
    public Result setPayPassword(@RequestBody ElectronicUserVo electronicUserVo,@RequestHeader String token){
        System.err.println(electronicUserVo);
        this.arElectronicService.setPayPassword(electronicUserVo,token);

        return Result.build(null,ResultCodeEnum.SUCCESS);
    }
    /**
     * 转账
     * @return
     */
    @PostMapping("/zhuanzhang")
    public Result zhaunzhang(@RequestBody ArElectronicBankCardVo arElectronicBankCardVo){
        this.arElectronicService.zhuanzhang(arElectronicBankCardVo);
            return Result.build(true,ResultCodeEnum.SUCCESS);
    }
    @PostMapping("/findName")
    public Result findName(@RequestBody ElectronicUserVo electronicUserVo,@RequestHeader String token){
        System.err.println(electronicUserVo);
        boolean name = this.arElectronicService.findName(electronicUserVo,token);
        if(name){
            return Result.build(electronicUserVo,ResultCodeEnum.SUCCESS);
        }
        return Result.build(electronicUserVo,ResultCodeEnum.USER_NAME_IS_EXISTS);

    }
    @PostMapping("/findNames/{relName}")
    public Result findNames(@PathVariable String relName,@RequestHeader String token){
        System.err.println(relName);
        boolean name = this.arElectronicService.findNames(relName,token);
        if(name){
            return Result.build(true,ResultCodeEnum.SUCCESS);
        }
        return Result.build(false,ResultCodeEnum.USER_NAME_IS_EXISTS);

    }
    @PostMapping("/findBankCard")
    public Result findBankCard(@RequestBody ArElectronicBankCardVo arElectronicBankCardVo, @RequestHeader String token){
        System.err.println("token：="+token);
        List<ArBankcardTypeVo> bankCards = this.arElectronicService.findBankCards(arElectronicBankCardVo,token);
        System.err.println("bankCards：="+bankCards);

        return Result.build(bankCards,ResultCodeEnum.SUCCESS);
    }
    @PostMapping("/findTypes")
    public Result findTypes(){
        List<ArCardtype> list = this.arCardtypeService.list();
        return Result.build(list,ResultCodeEnum.SUCCESS);
    }
    @PostMapping("/yzpassword")
    public Result yzpassword(@RequestBody ArBankCardPassword arBankCardPassword){
        System.err.println(arBankCardPassword);
        boolean a = this.arElectronicService.findPassword(arBankCardPassword);
        if (a){
            return Result.build(true,ResultCodeEnum.SUCCESS);
        }
        return Result.build(false,ResultCodeEnum.USER_NAME_IS_EXISTS);
    }
    @PostMapping("/yzBankCards")
    public Result yzBankCards(@RequestBody ArElectronicBankCardVo arElectronicBankCardVo){
        System.err.println(arElectronicBankCardVo);
        boolean a = this.arElectronicService.yzBankCards(arElectronicBankCardVo);
        if (a){
            return Result.build(true,ResultCodeEnum.SUCCESS);
        }
        return Result.build(false,ResultCodeEnum.USER_NAME_IS_EXISTS);
    }
    @PostMapping("/yzBalances")
    public Result yzBalances(@RequestBody Money money){
        System.err.println(money);
        Money a = this.arElectronicService.yzBalances(money);

        System.err.println(a);
        return Result.build(a,ResultCodeEnum.SUCCESS);
    }
    @PostMapping("/yzType")
    public Result yzType(@RequestBody ArElectronicBankCardVo arElectronicBankCardVo){
        System.err.println(arElectronicBankCardVo);
        String a = this.arElectronicService.yzType(arElectronicBankCardVo);
            return Result.build(a,ResultCodeEnum.SUCCESS);

    }
    @PostMapping("/findBalance/{bankCard}")
    public Result findBalance(@PathVariable String bankCard){
        Integer tids = this.arElectronicService.findTids(bankCard);
        String tname = this.arCardtypeService.findTname(tids);
        String balance = this.arElectronicService.findBalance(bankCard);
        Map<Object, Object> map=new HashMap<>();
        map.put("yi",tname);
        map.put("er",balance);
        System.err.println("map："+map);
        return Result.build(map,ResultCodeEnum.SUCCESS);
    }


}
